module.exports = (options) => {
	// 返回中间件函数
	return async function user(ctx, next) {
		let res = await ctx.$id.checkToken(ctx.event.token);
		const uid = res&&res.uid
		if(!res.uid){
			throw {
				code:201,
				message:'非法token'
			};
			return
		}
		let userinfos = await ctx.db.collection('uni-id-users').doc(uid).get();
		console.log('----- check_user -----',userinfos);
		if (userinfos.data.length === 0) {
			throw {
				code: 202,
				desc: '未查询到用户信息'
			}
			return
		}
		ctx.$userinfo = userinfos.data[0]
		await next();
	};
};
